﻿<%@ Page Title="" Language="C#" MasterPageFile="~/UI/Main/Main.Master" CodeBehind="Group.aspx.cs"
    Inherits="OrganizedIN.UI.GroupContact.Group" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <style type="text/css">
        .Header
        {
            background: #6D84B4;
            border: 1px solid #3B5998;
            color: white;
            font-size: 13px;
            font-weight: bold;
            margin: 0px;
            display: block;
            height: 25px;
            width: 99%;
        }
        .Header a, a:hover
        {
            color: white;
            font-size: 13px;
            font-weight: bold;
            text-decoration: underline;
            cursor: pointer;
        }
        .Header a:hover
        {
            color: white;
            font-size: 13px;
            font-weight: bold;
            text-decoration: underline;
            cursor: pointer;
        }
        .Header1
        {
            background: #5C85B5;
            border: 1px solid #3B5998;
            color: white;
            font-size: 11px;
            font-weight: bold;
            margin: 0px;
            display: block;
            height: 25px;
            width: 99%;
        }
        .Header1 a, a:hover
        {
            color: white;
            font-size: 11px;
            font-weight: bold;
            text-decoration: underline;
            cursor: pointer;
        }
        .Header1 a:hover
        {
            color: white;
            font-size: 11px;
            font-weight: bold;
            text-decoration: underline;
            cursor: pointer;
        }
        .Content
        {
            border: 1px solid #3B5998;
            width: 99%;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <script src="../../src/js/jquery.fcbkcomplete.js" type="text/javascript"></script>

    <script type="text/javascript">
        $(document).ready(function() {
            $(".addusers").fcbkcomplete({
                json_url: '<%=ResolveClientUrl("~/UI/ContactSuggest.ashx") %>',
                addontab: false,
                height: 2,
                complete_text: "Start Typing Contact Names...",
                onremove: "Remove",
                onselect: "Add"
            });
        });

        function Add(item, gid) {
            if ($("[id$=hdnSelected]").val().indexOf(item._value + "**" + gid) == -1)
                $("[id$=hdnSelected]").val($("[id$=hdnSelected]").val() + item._value + "**" + gid + "||");
        }

        function Remove(item, gid) {
            $("[id$=hdnSelected]").val($("[id$=hdnSelected]").val().replace(item._value + "**" + gid + "||", ""));
        }

        function CheckAddedContacts(gid) {
            if ($("[id$=hdnSelected]").val().indexOf("**" + gid) == -1) {
                alert("No Contacts Has Been Added Yet");
                return false;
            }
            else {
                return true;
            }
        }
    </script>

    <input type="hidden" id="hdnSelected" runat="server" />
    <asp:HyperLink ID="lnkGroup" runat="server" NavigateUrl="~/UI/GroupContact/CreateGroup.aspx"> Create Group</asp:HyperLink>
    <br />
    <br />
    <asp:Accordion ID="Accordion2" runat="server" SelectedIndex="0" FadeTransitions="true"
        FramesPerSecond="40" TransitionDuration="250" AutoSize="None" ContentCssClass="Content"
        HeaderCssClass="Header">
        <Panes>
            <asp:AccordionPane runat="server" ID="AccordionPane1">
                <Header>
                    <a href="" onclick="return false;">Group Requests</a>
                </Header>
                <Content>
                    <br />
                    <asp:Accordion ID="Accordion3" runat="server" SelectedIndex="0" FadeTransitions="true"
                        FramesPerSecond="40" TransitionDuration="250" AutoSize="None" ContentCssClass="Content"
                        HeaderCssClass="Header1">
                        <Panes>
                            <asp:AccordionPane runat="server" ID="AccordionPane2">
                                <Header>
                                    <a href="" onclick="return false;">Requests To Join Your Groups</a>
                                </Header>
                                <Content>
                                    <br />
                                    <asp:Repeater ID="rptrOwnerRequest" runat="server" OnItemDataBound="rptrOwnerRequest_ItemDataBound">
                                        <ItemTemplate>
                                            <asp:HiddenField ID="hdnReqGroupID" runat="server" Value='<%# Eval("Group_ID") %>' />
                                            <asp:Panel ID="pnlGroup" runat="server" GroupingText='<%# Eval("Group_Name") %>'>
                                                <asp:GridView ID="gvOwnerRequests" runat="server" EmptyDataText="No New Member Requests For This Group"
                                                    AllowPaging="True" AutoGenerateColumns="False" BorderColor="White" HeaderStyle-ForeColor="Purple"
                                                    PageSize="20" Width="80%" OnRowCommand="grdOwnRequest_RowCommand">
                                                    <HeaderStyle ForeColor="Purple" />
                                                    <RowStyle BorderColor="White" />
                                                    <Columns>
                                                        <asp:TemplateField HeaderStyle-BackColor="#c2cee7" HeaderStyle-Font-Bold="true" HeaderText="Contact Information">
                                                            <ItemTemplate>
                                                                <table width="100%">
                                                                    <tr>
                                                                        <td rowspan="3" width="10%">
                                                                            <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>'>
                                                                                <asp:ImageButton ID="imgUser" runat="server" Height="70px" ImageUrl='<%# Eval("ProfilePicture") %>'
                                                                                    Width="100%" /></a>
                                                                        </td>
                                                                        <td>
                                                                            <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>'>
                                                                                <asp:Label ID="lblUname" runat="server" Text='<%# Eval("Name") %>' Font-Bold="True"
                                                                                    Font-Size="13px" ForeColor="#6D84B4"></asp:Label></a> Wants To Join Your
                                                                            Group
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblGender" Text='<%# Eval("Gender") %>' runat="server"></asp:Label>
                                                                            ,
                                                                            <asp:Label ID="lblDOB" Text='<%# Eval("DOB") %>' runat="server"></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td>
                                                                            <asp:Label ID="lblEmail" runat="server" Text='<%# Eval("username") %>'></asp:Label>
                                                                        </td>
                                                                    </tr>
                                                                </table>
                                                            </ItemTemplate>
                                                            <HeaderStyle BackColor="#C2CEE7" Font-Bold="True"></HeaderStyle>
                                                        </asp:TemplateField>
                                                        <asp:TemplateField HeaderStyle-BackColor="#c2cee7" HeaderStyle-Font-Bold="true" HeaderStyle-Width="50px"
                                                            ItemStyle-VerticalAlign="Middle">
                                                            <ItemTemplate>
                                                                <asp:ImageButton ID="btnConfirm" runat="server" CommandArgument='<%# Eval("GCID") %>'
                                                                    CommandName="confirm" ImageUrl="~/images/accept.png" ToolTip="Allow" />
                                                                <asp:ImageButton ID="btnDelete" CommandName="reject" CommandArgument='<%# Eval("GCID") %>'
                                                                    runat="server" ImageUrl="~/images/delete.png" ToolTip="Reject" />
                                                            </ItemTemplate>
                                                            <HeaderStyle BackColor="#C2CEE7" Font-Bold="True" />
                                                            <ItemStyle VerticalAlign="Top"></ItemStyle>
                                                        </asp:TemplateField>
                                                    </Columns>
                                                </asp:GridView>
                                            </asp:Panel>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                    <br />
                                </Content>
                            </asp:AccordionPane>
                            <asp:AccordionPane runat="server" ID="AccordionPane3">
                                <Header>
                                    <a href="" onclick="return false;">Invitations To Join Other Groups</a>
                                </Header>
                                <Content>
                                    <br />
                                    <asp:Repeater ID="rptrMemberRequest" runat="server" OnItemCommand="rptrMemberRequest_ItemCommand">
                                        <HeaderTemplate>
                                            <table width="95%" cellpadding="0" style="border: 1px solid #3B5998;" cellspacing="0">
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <tr>
                                                <td>
                                                    <asp:Label ID="lblUname" runat="server" Text='<%# Eval("Group_Name") %>' Font-Bold="True"
                                                        Font-Size="13px" ForeColor="#6D84B4"></asp:Label><br />
                                                    <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>'>
                                                        <asp:Label ID="lblOwner" runat="server" Text='<%# Eval("Owner") %>' Font-Bold="True"
                                                            Font-Size="11px" ForeColor="#6C74C3"></asp:Label></a>
                                                </td>
                                                <td align="right" style="border-left-style: solid; border-left-width: 1px; border-left-color: #000000"
                                                    width="50px">
                                                    <asp:ImageButton ID="btnConfirm" runat="server" CommandArgument='<%# Eval("GCID") %>'
                                                        CommandName="confirm" ImageUrl="~/images/accept.png" ToolTip="Allow" />
                                                    <asp:ImageButton ID="btnDelete" CommandName="reject" CommandArgument='<%# Eval("GCID") %>'
                                                        runat="server" ImageUrl="~/images/delete.png" ToolTip="Reject" />
                                                </td>
                                            </tr>
                                            <tr>
                                                <td colspan="2" style="height: 1px; background-color: Black">
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                        <FooterTemplate>
                                            </table>
                                        </FooterTemplate>
                                    </asp:Repeater>
                                    <br />
                                </Content>
                            </asp:AccordionPane>
                        </Panes>
                    </asp:Accordion>
                    <br />
                </Content>
            </asp:AccordionPane>
            <asp:AccordionPane runat="server" ID="apSrchGrp">
                <Header>
                    <a href="" onclick="return false;">Search Groups </a>
                </Header>
                <Content>
                    <table width="100%">
                        <tr>
                            <td width="20%">
                                <b>Enter Search Phrase</b>
                            </td>
                            <td>
                                <asp:TextBox ID="txtSearch" runat="server" Width="373px"></asp:TextBox><asp:RequiredFieldValidator
                                    ID="rfvSearch" runat="server" ErrorMessage="*" Display="Dynamic" ValidationGroup="search"
                                    ControlToValidate="txtSearch"></asp:RequiredFieldValidator>
                                &nbsp;&nbsp;&nbsp;
                                <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click"
                                    ValidationGroup="search" />&nbsp;<asp:Label ID="lblError" runat="server" ForeColor="Red"
                                        Text=""></asp:Label>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <asp:Repeater ID="rptrGroups" runat="server">
                                    <HeaderTemplate>
                                        <table width="95%" cellpadding="0" style="border: 1px solid #3B5998;" cellspacing="0">
                                            <tr>
                                                <td colspan="2" style="background-color: #6D84B4; color: #FFFFFF; font-weight: bold;
                                                    font-family: arial, Helvetica, sans-serif; font-size: medium;">
                                                    Group Search Result
                                                </td>
                                            </tr>
                                    </HeaderTemplate>
                                    <ItemTemplate>
                                        <tr>
                                            <td width="85%">
                                                <asp:Label ID="lblUname" runat="server" Text='<%# Eval("Group_Name") %>' Font-Bold="True"
                                                    Font-Size="13px" ForeColor="#6D84B4"></asp:Label><br />
                                                <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>'>
                                                    <asp:Label ID="lblOwner" runat="server" Text='<%# Eval("Owner") %>' Font-Bold="True"
                                                        Font-Size="11px" ForeColor="#6C74C3"></asp:Label></a>
                                                <asp:Label ID="lblErr" runat="server"></asp:Label>
                                            </td>
                                            <td align="right" style="border-left-style: solid; border-left-width: 1px; border-left-color: #000000">
                                                <asp:ImageButton ID="btnAdd" runat="server" Title="Join Group" Visible='<%# !Convert.ToBoolean(Eval("IsMember").ToString())  %>'
                                                    CommandArgument='<%# Eval("Group_ID") %>' CommandName="select" ImageUrl="~/images/icon-join1.png"
                                                    OnClick="btnAdd_Click" />
                                                <asp:Label ID="lblWaiting" runat="server" ForeColor="Red" Visible='<%# Eval("IsPending") %>'><br />Waiting For Group Admin's Approval</asp:Label>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td colspan="2" style="height: 1px; background-color: Black">
                                            </td>
                                        </tr>
                                    </ItemTemplate>
                                    <FooterTemplate>
                                        </table>
                                    </FooterTemplate>
                                </asp:Repeater>
                            </td>
                        </tr>
                    </table>
                </Content>
            </asp:AccordionPane>
            <asp:AccordionPane runat="server" ID="apExstGrp">
                <Header>
                    <a href="" onclick="return false;">Existing Groups </a>
                </Header>
                <Content>
                    <br />
                    <asp:Accordion ID="Accordion1" runat="server" SelectedIndex="0" FadeTransitions="true"
                        FramesPerSecond="40" TransitionDuration="250" AutoSize="None" ContentCssClass="Content"
                        HeaderCssClass="Header1">
                        <Panes>
                            <asp:AccordionPane runat="server" ID="apOwner">
                                <Header>
                                    <a href="" onclick="return false;">Owner Groups </a>
                                </Header>
                                <Content>
                                    <asp:Label ID="lblOwnerError" runat="server"></asp:Label>
                                    <asp:Repeater ID="rptrGroupUsers" runat="server" OnItemDataBound="rptrUsers_ItemDataBound"
                                        OnItemCommand="rptrGroupUsers_ItemCommand">
                                        <ItemTemplate>
                                            <asp:HiddenField ID="hdnGroupID" runat="server" Value='<%# Eval("Group_ID") %>' />
                                            <asp:Panel ID="pnlGroup" runat="server" GroupingText='<%# Eval("Group_Name") %>'>
                                                <asp:Repeater ID="rptrUsers" runat="server">
                                                    <HeaderTemplate>
                                                        <ul class="holder1">
                                                    </HeaderTemplate>
                                                    <ItemTemplate>
                                                        <li class="bit-box1">
                                                            <center>
                                                                <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>'>
                                                                    <asp:Image ID="Image1" runat="server" ToolTip='<%# Eval("Name") %>' Style="display: inline"
                                                                        ImageUrl='<%# Eval("ProfilePicture") %>' Height="60px" Width="50px" /><br />
                                                                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>' Font-Bold="True"
                                                                        Font-Size="13px" ForeColor="#6D84B4"></asp:Label></a> <a title="Remove Contact From Group"
                                                                            href='<%# String.Format("?action=Remove&uid={0}&gid={1}",Eval("username"),Eval("GroupID")) %>'
                                                                            class="closebutton" runat="server" visible='<%# GetLabelVisibility(Eval("IsOwner")) %>'>
                                                                        </a>
                                                                <asp:Label ID="lblOwner" runat="server" Font-Bold="True" Visible='<%# Eval("IsOwner") %>'
                                                                    Font-Size="11px" ForeColor="#6D84B4"><br />( Owner )</asp:Label>
                                                                <asp:Label ID="lblOwnWaiting" runat="server" Visible='<%# GetLabelVisibility(Eval("IsApproved")) %>'
                                                                    ForeColor="Red"><br />User Approval Pending !</asp:Label>
                                                            </center>
                                                        </li>
                                                    </ItemTemplate>
                                                    <FooterTemplate>
                                                        </ul>
                                                    </FooterTemplate>
                                                </asp:Repeater>
                                                <asp:TextBox ID="tbAddUsers" class="addusers" ToolTip='<%# Eval("Group_ID") %>' runat="server"></asp:TextBox>
                                                <asp:Button ID="btnAddContact" ToolTip="Add Selected Contacts To Group" CommandName="addusers"
                                                    CssClass="a" Text="Add Contacts" OnClientClick='<%# String.Format("return CheckAddedContacts({0});",Eval("Group_ID")) %>'
                                                    runat="server" CommandArgument='<%# Eval("Group_ID") %>' />
                                                <asp:ImageButton ID="btnDelete" runat="server" ToolTip="Delete Group" CommandArgument='<%# Eval("Group_ID") %>'
                                                    Height="13px" Width="13px" CommandName="Delete" ImageUrl="~/images/brights-brights_icons-delete.ico-96x96.png" />
                                            </asp:Panel>
                                        </ItemTemplate>
                                    </asp:Repeater>
                                </Content>
                            </asp:AccordionPane>
                            <asp:AccordionPane runat="server" ID="apMember">
                                <Header>
                                    <a href="" onclick="return false;">Member Groups </a>
                                </Header>
                                <Content>
                                    <asp:GridView ID="gvGrps" runat="server" EmptyDataText="No Groups Added Yet" AllowPaging="true"
                                        AutoGenerateColumns="false" BorderColor="White" HeaderStyle-ForeColor="Purple"
                                        PageSize="20" Width="95%" OnRowDataBound="gvGrps_RowDataBound" OnRowCommand="gvGrps_RowCommand">
                                        <HeaderStyle ForeColor="Purple" />
                                        <RowStyle BorderColor="White" />
                                        <Columns>
                                            <asp:TemplateField HeaderStyle-BackColor="#c2cee7" HeaderStyle-Font-Bold="true" HeaderText="Group Information">
                                                <ItemTemplate>
                                                    <asp:HiddenField ID="hdnGroupID" runat="server" Value='<%# Eval("Group_ID") %>' />
                                                    <asp:Panel ID="pnlGroup" runat="server" GroupingText='<%# Eval("Group_Name") %>'
                                                        Enabled='<%# Eval("IsApproved") %>'>
                                                        <asp:Repeater ID="rptrUsers" runat="server">
                                                            <HeaderTemplate>
                                                                <ul class="holder1">
                                                            </HeaderTemplate>
                                                            <ItemTemplate>
                                                                <li class="bit-box2">
                                                                    <center>
                                                                        <a href='<%# String.Format("../Profile/MyProfile.aspx?uid={0}",Eval("username")) %>'>
                                                                            <asp:Image ID="Image1" runat="server" Style="display: inline" ImageUrl='<%# Eval("ProfilePicture") %>'
                                                                                Height="60px" Width="50px" /><br />
                                                                            <asp:Label ID="Label1" Width="70px" runat="server" Text='<%# Eval("Name") %>' Font-Bold="True"
                                                                                Font-Size="11px" ForeColor="#6D84B4"></asp:Label>
                                                                            <asp:Label ID="lblOwner" runat="server" Font-Bold="True" Visible='<%# Eval("IsOwner") %>'
                                                                                Font-Size="11px" ForeColor="#6D84B4"><br />( Owner )</asp:Label>
                                                                        </a>
                                                                    </center>
                                                                </li>
                                                            </ItemTemplate>
                                                            <FooterTemplate>
                                                                </ul>
                                                            </FooterTemplate>
                                                        </asp:Repeater>
                                                        <asp:Label ID="lblMemWaiting" runat="server" Text="Group Admin's Approval is Pending"
                                                            ForeColor="Red" Visible='<%# GetLabelVisibility(Eval("IsApproved")) %>'></asp:Label>
                                                    </asp:Panel>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderStyle-BackColor="#c2cee7" HeaderStyle-Font-Bold="true" HeaderStyle-Width="10%"
                                                ItemStyle-VerticalAlign="Top">
                                                <ItemTemplate>
                                                    <asp:ImageButton ID="btnDelete" CommandName="remove" CommandArgument='<%# Eval("Group_ID") %>'
                                                        runat="server" ImageUrl="~/images/brights-brights_icons-delete.ico-96x96.png"
                                                        Height="16px" Width="16px" ToolTip="Unjoin Group" />
                                                </ItemTemplate>
                                                <HeaderStyle BackColor="#C2CEE7" Font-Bold="True" />
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>
                                </Content>
                            </asp:AccordionPane>
                        </Panes>
                    </asp:Accordion>
                    <br />
                </Content>
            </asp:AccordionPane>
        </Panes>
    </asp:Accordion>
    <br />
    <br />
    <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/UI/GroupContact/CreateGroup.aspx"> Create Group</asp:HyperLink>
</asp:Content>
